from ChessBoard import *
import time
import sys

## http://mail.python.org/pipermail/python-list/2007-May/438106.html
class Tee(object):
    def __init__(self):
        self.lines = []
        self.stdout = sys.stdout
        sys.stdout = self
    def __del__(self):
        sys.stdout = self.stdout
    def write(self, data):
        self.lines.extend(data)
        self.stdout.write(data)

#plays a game of chess, which it reads from a file.

'''
 this code reads the moves in and the expected results 
 the tee object intercepts stdout and captures the print from 
 the printSingleRow() method

 after all the moves are complete, the expected results are
 compared with the captured output

'''

chessboard = ChessBoard()

f = open('moves.txt', 'r')

moves = []

for line in f:
    moves.extend((line.rstrip()).split(" "))

f.close()

f = open('results.txt', 'r')
results = []

for line in f:
    results.extend(line)

f.close

tee = Tee()

for move in moves:
    chessboard.printBoardSingleRow()
    print ' '
    chessboard.addTextMove(move)

for i in range (len(results)):
    if results[i] != tee.lines[i]:
        print "Invalid at %d" % i

